<template>
	<view class="content">
		<view class="box1">
			<view class="row">
				<text class="liyuandian">总资产（FIL)</text>
				<text class="liyuandian">今日收益（FIL)</text>
			</view>
			<view class="row1">
				<text>{{assets}}</text>
				<text>+{{today_profit}}</text>
			</view>
			<view class="row2">
				<view class="minibox" @tap="jumpchongzhi">
					<image src="../../static/icon/chongzhi.png" mode=""></image>
					<text>充值</text>
				</view>
				<view class="minibox" @tap="jumptibi">
					<image src="../../static/icon/tibi.png" mode=""></image>
					<text>提币</text>
				</view>
				<view class="minibox" @tap="huazhuanopen">
					<image src="../../static/icon/huazhuang.png" mode=""></image>
					<text>划转</text>
				</view>
				
			</view>
		</view>
		<view class="box2">
			<view class="box2_row1">
				<view class="zuo">
					<image src="../../static/icon/filecoin-logo@2x.png" mode=""></image>
					<text>资金账户</text>
				</view>
				<view class="you" @tap="jumpfiljilu">
					资金记录
				</view>
			</view>
			<view class="box2_row2">
				<view class="box2item">可用余额</view>
				<view class="box2item">待释放</view>
				<view class="box2item">冻结</view>
			</view>
			<view class="box2_row2">
				<view class="box2item">{{valid_fil}}</view>
				<view class="box2item">{{wait_fil}}</view>
				<view class="box2item">{{frozen_fil}}</view>
			</view>
		</view>
		<view class="box2">
			<view class="box2_row1">
				<view class="zuo">
					<image src="../../static/icon/fil2.png" mode=""></image>
					<text>消耗账户</text>
				</view>
				<view class="you" @tap="jumpxiaohaojilu">
					资金记录
				</view>
			</view>
			<view class="box2_row2">
				<view class="box2item">可消耗</view>
				<view class="box2item">累计质押</view>
				<view class="box2item">累计Gas</view>
			</view>
			<view class="box2_row2">
				<view class="box2item">{{consume_fil}}</view>
				<view class="box2item">{{pledge_fil}}</view>
				<view class="box2item">{{gas_fil}}</view>
			</view>
		</view>
		<!-- 划转对话框 -->
		<view class="huazhuang" v-if="ishuazhuang" @tap="ishuazhuang=!ishuazhuang">
			
		</view>
		<view class="huazhuangbox" v-if="ishuazhuang">
			<view class="huazhuangboxrow1">
				<view class="" @tap="jumpHuazhuangjilu">查看划转记录</view>
				<image @tap="jumpHuazhuangjilu" src="../../static/icon/zuojiantou.png" mode=""></image>
			</view>
			<view class="huazhuangboxrow2">
				<view class="huazhuangboxrow2_1">
					<view class="huazhuangboxrow2_1_zuo">
						<view>从 <text>{{zh1}}</text></view>
						<view>{{zh1_f}}FIL</view>
					</view>
					<image src="../../static/icon/xunhuan.png" mode="" @click="jiaohuan"></image>
					<view class="huazhuangboxrow2_1_you">
						<view>到 <text> {{zh2}}</text></view>
						<view>{{zh2_cf}}FIL</view>
					</view>
				</view>
			</view>
			<view class="huazhuangboxrow3">
				数量
			</view>
			<view class="huazhuangboxrow4">
				<input type="text" v-model="num" placeholder="请输入划转数量"/>
				<text @click="quanbuhuazhuan">全部</text>
			</view>
			<view class="huazhuangboxrow5" @click="huazhuantijiao">
				划转
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ishuazhuang:false,
				assets:'',
				today_profit:'',
				valid_fil:'',
				wait_fil:'',
				frozen_fil:'',
				consume_fil:'',
				pledge_fil:'',
				gas_fil:'',
				zh1:'消耗账户',
				zh2:'资金账户',
				zh1_f:'',
				zh2_cf:'',
				consume_fil1:'',
				fil:'',
				num:'',
			}
		},
		onLoad() {
			this.getinfo()
			this.gethuazhuanginfo()
		},
		onShow() {
			this.gethuazhuanginfo()
			
		},
		methods: {
			getinfo(){
				var token =uni.getStorageSync('token')
				if(token==''||token==null){
					uni.reLaunch({
					    url:'../login/login'
					})
				}else{
					this.http({
					 	url:'/api/User/wallet',
					 	method:'POST',
						header:{
							'token':token
						},
					 	success:(res)=>{
							console.log(res)
							this.assets = res.data.assets
							this.today_profit = res.data.today_profit 
							this.valid_fil = res.data.valid_fil 
							this.wait_fil = res.data. wait_fil 
							this.frozen_fil = res.data.frozen_fil 
							this.consume_fil = res.data.consume_fil
							this.pledge_fil = res.data.pledge_fil
							this.gas_fil = res.data.gas_fil 
						},
					 	error:()=>{
					 		uni.showToast({
					 			title:"请求异常"	
					 		})
					 	},	
					 })
				} 
			},
			gethuazhuanginfo(){
				var token =uni.getStorageSync('token')
				if(token==''||token==null){
					uni.reLaunch({
					    url:'../login/login'
					})
				}else{
					this.http({
					 	url:'/api/Trade/transferFIL',
					 	method:'POST',
						header:{
							'token':token
						},
					 	success:(res)=>{
							console.log(res)
							
							this.consume_fil1 = res.data.consume_fil
							this.fil =res.data.fil
							this.zh1_f = this.consume_fil1 
							this.zh2_cf =this.fil
						},
					 	error:()=>{
					 		uni.showToast({
					 			title:"请求异常"	
					 		})
					 	},	
					 })
				} 
			},
			huazhuanopen(){
				var tt=this
				tt.ishuazhuang=!tt.ishuazhuang
				tt.num =''
				tt.zh1_f =tt.consume_fil1
				tt.zh2 = '资金账户'
				tt.zh2_cf = tt.fil
				tt.zh1 ='消耗账户'
				
			},
			jiaohuan(){
				
				var tt=this
				tt.num =''
				if(tt.zh1 =='消耗账户'){
					tt.zh1='资金账户';tt.zh1_f =tt.fil;tt.zh2 ='消耗账户';tt.zh2_cf =tt.consume_fil1
				}else{
					tt.zh1_f =tt.consume_fil1
					tt.zh2 = '资金账户'
					tt.zh2_cf = tt.fil
					tt.zh1 ='消耗账户'
				}
			},
			quanbuhuazhuan(){
				var tt=this
				if(tt.zh1 =='消耗账户'){
					tt.num =tt.consume_fil1
				}else if(tt.zh1 =='资金账户'){
					tt.num =tt.fil
				}
			},
			huazhuantijiao(){
				var tt = this
				
				var token =uni.getStorageSync('token')
				if(token==''||token==null){
					uni.reLaunch({
					    url:'../login/login'
					})
				}else{
					if(tt.zh1 =='消耗账户'){
						this.http({
						 	url:'/api/Trade/transfer',
						 	method:'POST',
							header:{
								'token':token
							},
							data:{
								num:tt.num,
								point:1
							},
						 	success:(res)=>{
								console.log(res)
								console.log('11111111111')
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
								setTimeout(()=>{
									this.getinfo()
									this.ishuazhuang = false
								},1000)
								
							},
						 	error:()=>{
						 		uni.showToast({
						 			title:"请求异常"	
						 		})
						 	},	
						 })
					}else if(tt.zh1 =='资金账户'){
						this.http({
						 	url:'/api/Trade/transfer',
						 	method:'POST',
							header:{
								'token':token
							},
							data:{
								num:tt.num,
								point:2
							},
						 	success:(res)=>{
								console.log(res)
								console.log('2222222222')
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
								setTimeout(()=>{
									this.getinfo()
									this.ishuazhuang = false
								},1000)
								
								
							},
						 	error:()=>{
						 		uni.showToast({
						 			title:"请求异常"	
						 		})
						 	},	
						 })
					}
					
				} 
			},
			jumpHuazhuangjilu(){
				uni.navigateTo({
						url:'./huazhuanjilu'
				})
			},
			jumpchongzhi(){
				uni.navigateTo({
					url:'./chongzhi/chongzhi'
				})
			},
			jumpxiaohaojilu(){
				uni.navigateTo({
					url:'./xiaohaojilu'
				})
			},
			jumpfiljilu(){
				uni.navigateTo({
					url:'./filjilu?currentIndex=0'
				})
			},
			jumptibi(){
				uni.navigateTo({
					url:'./tibi/tibi'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC;
		font-weight: 500;
		.box1{
			width: 690rpx;
			height: 300rpx;
			background: #0072FF;
			border-radius: 5px;
			.row,.row1{
				width:587rpx;
				margin: 0 auto;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.liyuandian{
					padding-top: 30rpx;
				}
				text{
					
					font-size: 30rpx;
					color: #FFFFFF;
				}
			}
			.row1{
				font-size: 32rpx;
				font-weight: bold;
				margin: 20rpx auto;
			}
			.row2{
				width: 640rpx;
				margin: 61rpx auto;
				display: flex;
				justify-content:space-between;
				.minibox{
					width: 180rpx;
					height: 70rpx;
					background: #FFFFFF;
					border-radius: 10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32rpx;
					font-weight: bold;
					color: #0072FF;
					image{
						width: 49rpx;
						height: 49rpx;
						margin-right: 20rpx;
					}
				}
			}
		}
		.box2{
			width: 690rpx;
			height: 200rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 3px 0px rgba(43, 43, 43, 0.18);
			border-radius: 10rpx;
			margin: 50rpx auto 0 auto;
			.box2_row1{
				width: 630rpx;
				margin: auto;
				margin-bottom: 27rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.zuo{
					display: flex;
					align-items: center;
					margin-top: 25rpx;
					image{
						width: 59rpx;
						height: 59rpx;
					}
					text{
						margin-left: 20rpx;
					}
				}
				.you{
					margin-top: 25rpx;
					width: 150rpx;
					height: 46rpx;
					background: #0072FF;
					border-radius: 8rpx;
					font-size: 26rpx;
					color: #FFFFFF;
					line-height: 46rpx;
					text-align: center;
				}
			}
			.box2_row2{
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin: 0 auto 10rpx auto;
				.box2item{
					font-size: 26rpx;
					flex: 1;
					text-align: center;
				}
			}
		}
		.huazhuang{
			width: 100%;
			height: 100%;
			background: rgba(0,0,0,0.5);
			position: fixed;
			top: 0;
			left: 0;
		}
		.huazhuangbox{
			width: 750rpx;
			height: 595rpx;
			background: #FFFFFF;
			border-radius: 25px 25px 0px 0px;
			position: fixed;
			bottom: 0;
			left: 0;
			opacity: 1;
			.huazhuangboxrow1{
				padding-top: 30rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end ;
				margin-right: 72rpx;
				image{
					width: 14px;
					height: 14px;
					margin-left:15rpx ;
				}
			}
			.huazhuangboxrow2{
				width: 690rpx;
				height: 128rpx;
				background: #FFFFFF;
				box-shadow: 0px 0px 3px 0px rgba(43, 43, 43, 0.18);
				border-radius: 5px;
				margin: 40rpx auto;
				.huazhuangboxrow2_1{
					width: 624rpx;
					height: 128rpx;
					margin: auto;
					display: flex;
					justify-content: space-between;
					align-items: center;
					text-align: center;
					image{
						width: 54rpx;
						height: 54rpx;
					}
				}
			}
			.huazhuangboxrow3{
				margin-left:30rpx ;
				font-size: 28rpx;
				font-weight: bold;
			}
			.huazhuangboxrow4{
				width: 630rpx;
				height: 79rpx;
				background: #CCCCCC;
				box-shadow: 0px 0px 3px 0px rgba(43, 43, 43, 0.18);
				border-radius: 5px;
				margin: 30rpx auto 40rpx auto;
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				input{
					flex: 1;
				}
			}
			.huazhuangboxrow5{
				width: 690rpx;
				height: 80rpx;
				background: #0072FF;
				border-radius: 10rpx;
				font-size: 36rpx;
				font-weight: bold;
				color: #FFFFFF;
				line-height: 80rpx;
				margin: 0 auto 50rpx auto;
				text-align: center;
			}
		}
	}

	
</style>
